﻿using LxBasic;
using LxCore;

namespace LxCore.Samples
{
    public class SolidCuboidHeatConduction : SampleVMBase
    {
        public SolidCuboidHeatConduction() : base()
        {
            Name = "长方体导热";
            FileName = "Case0-Chang.msh";
        }
        public override void RunCase()
        {
            ReadFile();
            LxSim.Sim.Info.ProjName = "固体导热";
            //create physical model
            var physical = LxSim.Sim.Physics.CreatePhysicalModel();
            physical.PhysicalType = PhysicalTypes.固体;
            physical.IsEnergyEnabled = true;

            //set zone condition
            var z = FindZone("BODY");
            ResHelper.GetCond(z).PhysicalModel = physical;

            var t_IN = FindBound(z, "IN");
            var tinset = ResHelper.GetCond(t_IN);
            tinset.WallThermalType = WallThermalTypes.定热流密度;
            tinset.HeatFlux_b = new ConstField.Double(300);

            var t_OUT = FindBound(z, "OUT");
            var toutset = ResHelper.GetCond(t_OUT);
            toutset.WallThermalType = WallThermalTypes.定壁温;
            toutset.Temperature = new ConstField.Double(300);

            var t_around = FindBound(z, "AROUND");
            //set monitor
            var monitor = LxSim.Sim.Monitors.CreateMonitor("IN面温度", StatisticTypes.AreaAverage);
            monitor.ScalarType = ScalarFieldTypes.Temperature;
            monitor.SetSelector(t_IN, true);
            LxSim.Sim.Monitors.CreateMonitor("时间", StatisticTypes.CostTime);
            //
            var graph = LxSim.Sim.Visuals.CreateGraph("边界温度");
            graph.GraphType = GraphTypes.等值图;
            graph.ScalarType = ScalarFieldTypes.Temperature;
            graph.SetSelector(t_IN, true);
            graph.SetSelector(t_OUT, true);
            graph.SetSelector(t_around, true);

            //run computation
            LxSim.Sim.Steps.IterationStep.MaxStepRule.MaxStep = 100;
            MultiThreads.SetThreadsCount(1);
            //LxSim.Sim.SolveCenter.TemperatureGroup.SolverType = LxLESS.IterationTypes.Jacobi;
            //加载到界面
            RunSimulation();
        }
    }
}
